package com.dsx.myblog;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;

public class DsxExecutor implements Executor {



    public static void main(String[] args) throws InterruptedException {


        Thread t = new Thread();
        t.getState();
        t.wait();
//        LockSupport.
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,10,
                1,TimeUnit.SECONDS, new ArrayBlockingQueue<>(5));
        long start = System.currentTimeMillis();
        List<Integer> list = new ArrayList<>();
        for (int i=0; i<10000; i++){
            final int j = i;
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(1000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    list.add(j);
                }
            };
            threadPoolExecutor.execute(runnable);
        }

        threadPoolExecutor.shutdown();
        threadPoolExecutor.awaitTermination(1, TimeUnit.DAYS);
        long end = System.currentTimeMillis();
        System.out.println("time: "+ (end - start) + " count: " + list.size());



    }
    @Override
    public void execute(Runnable command) {
        command.run();
    }
}



interface ff{
    void f();
}
class fff implements ff{

    @Override
    public void f() {

    }
}










